import { httpGet, httpPost, httpPut, httpDel } from "@/appBase/request";
import { toData, toPageData, toPageQueryParam } from "@/appBase/utils";
import config from '@/config';

/**
 * 下载文件url
 */
export const commonDownload = '/common/download';

/**
 * 查询分类列表
 * @param {Object} params
 * @param {String} params.type 模块类型（1-产教融合新闻 2-社区公共服务新闻 3-社群公共服务视频 4-资源库）
 */
export function queryCategoryTree(params) {
    const result = {"msg":"操作成功","code":200,"data":[{"name":"汽车制造专业群","id":"890775595330789376","parentId":"0","sortNo":6,"children":[{"name":"专业基础平台课程","id":"895959319253704704","parentId":"890775595330789376","sortNo":19,"children":[]},{"name":"专业核心课程","id":"895959426334285824","parentId":"890775595330789376","sortNo":20,"children":[]},{"name":"专业方向课程","id":"895959526271967232","parentId":"890775595330789376","sortNo":21,"children":[]},{"name":"市级在线精品开放课程","id":"898247640084340736","parentId":"890775595330789376","sortNo":27,"children":[]},{"name":"公共基础课程","id":"906528477434044416","parentId":"890775595330789376","sortNo":100,"children":[]}]},{"name":"现代服务专业群","id":"890775892862132224","parentId":"0","sortNo":8,"children":[{"name":"专业基础平台课程","id":"895959665711603712","parentId":"890775892862132224","sortNo":22,"children":[]},{"name":"专业核心课程","id":"895959774784479232","parentId":"890775892862132224","sortNo":23,"children":[]},{"name":"专业方向课程","id":"895959832472936448","parentId":"890775892862132224","sortNo":24,"children":[]},{"name":"在线精品开放课程","id":"905465512572968960","parentId":"890775892862132224","sortNo":67,"children":[]},{"name":"公共基础课程","id":"906595839831531520","parentId":"890775892862132224","sortNo":101,"children":[]}]},{"name":"涉农培训","id":"901051413709545472","parentId":"0","sortNo":44,"children":[{"name":"老年教学","id":"903650639069405184","parentId":"901051413709545472","sortNo":48,"children":[]},{"name":"生猪养殖培训","id":"905463824789233664","parentId":"901051413709545472","sortNo":66,"children":[]},{"name":"农业生产技术","id":"906110734285889536","parentId":"901051413709545472","sortNo":91,"children":[]}]},{"name":"教学实用技术","id":"906861428068147200","parentId":"0","sortNo":118,"children":[]}]};
    return  Promise.resolve(toData(result));
    // return httpGet(`/common/category/tree`, params).then((result) => toData(result));
}

/**
 * 新增分类
 * @param {Object} params
 * @param {String} params.id 
 * @param {String} params.code 分类编码
 * @param {String} params.name 分类名称
 * @param {String} params.parentId 父节点ID
 * @param {String} params.picUrl 图片地址
 * @param {String} params.name 分类名称
 * @param {Number} params.status 状态(1-正常 -1停用)
 * @param {Number} params.type 模块类型（1-产教融合新闻 2-社区公共服务新闻 3-社群公共服务视频 4-资源库）
 */
export function addCategoryTreeNode(params) {
    return httpPost(`/common/category`, params).then((result) => toData(result));
}

/**
 * 修改分类
 * @param {Object} params
 * @param {String} params.id 
 * @param {String} params.code 分类编码
 * @param {String} params.name 分类名称
 * @param {String} params.parentId 父节点ID
 * @param {String} params.picUrl 图片地址
 * @param {String} params.name 分类名称
 * @param {Number} params.status 状态(1-正常 -1停用)
 * @param {Number} params.type 模块类型（1-产教融合新闻 2-社区公共服务新闻 3-社群公共服务视频 4-资源库）
 */
export function updateCategoryTreeNode(params) {
    return httpPut(`/common/category`, params).then((result) => toData(result));
}

/**
 * 查询分类详情
 * @param {Object} params 
 * @param {String} params.id 
 * @returns 
 */
export function queryCategoryTreeNode(params) {
    return httpGet(`/common/category/${params.id}`).then((result) => toData(result));
}

/**
 * 删除分类
 * @param {Object} params 
 * @param {String} params.id 
 * @returns 
 */
export function delCategoryTreeNode(params) {
    return httpDel(`/common/category/${params.id}`).then((result) => toData(result));
}

/**
 * 交换排序分类排序
 * @param {Object} params 
 * @param {String} params.maxId 业务Id(排序号大的)
 * @param {String} params.maxSortNo 排序号大的
 * @param {String} params.minId 业务Id(排序号小的)
 * @param {String} params.minSortNo 排序号小的
 * 
 * @returns 
 */
export function updateCategoryTreeNodeSort(params) {
    return httpPut(`/common/category/sort`,params).then((result) => toData(result));
}

/**
 * 通用文件上传
 * @param {Object} params
 * @param {String} params.file 文件
 * @param {String} params.resourceBizType 文件资源类型  
 */
export function filesUpload(params) {
    const t = parseInt(Math.random()*1000);
    return httpPost(`/common/files-upload?_t=${t}`, params).then((result) => toData(result));
}

/**
 * 通用上传
 * @returns 
 */
export function basePost(url, param) {
    return httpPost(url, param).then((result) => toData(result));
}

// 文件在线预览
export function onlinePreview(url) {
    return `${config.fileViewRoot}/onlinePreview?url=${url}`;
}
